package com.mtl.bookt.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.mtl.common.tool.api.R;
import com.mtl.common.tool.model.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.mtl.bookt.domain.BookInfo;
import com.mtl.bookt.service.IBookInfoService;
import java.util.List;
import java.util.Arrays;
import java.util.Map;

/**
 *  控制器
 *
 * @author lsc
 * @since 2019-07-03
 */
@RestController
@RequestMapping("/bookinfo")
@Api(value = "图书管理", tags = "图书接口")
public class BookInfoController {
    @Autowired
	private IBookInfoService bookInfoService;

	/**
	* 详情
	*/
	@GetMapping("/detail")
	@ApiOperation(value = "详情", notes = "传入bookInfo", position = 1)
	public R<BookInfo> detail(Integer id) {
		BookInfo detail = bookInfoService.findById(id);
		return R.data(detail);
	}

	/**
	* 分页 
	*/
	@PostMapping("/page")
	@ApiOperation(value = "分页", notes = "传入bookInfo", position = 2)
//	public R<Page<BookInfo>> page(Integer page,Integer size) {
//		Page<BookInfo> pages = bookInfoService.findPage(page,size);
//		return R.data(pages);
//	}
	public R<Page<BookInfo>> page(@RequestBody Map<String,Object> param) {
		Page<BookInfo> pages = bookInfoService.findPage(param);
		return R.data(pages);
	}


	/**
	* 新增或修改 
	*/
	@PostMapping("/submit")
	@ApiOperation(value = "新增或修改", notes = "传入bookInfo", position = 6)
	public R submit(@RequestBody BookInfo bookInfo) {
		return R.status(bookInfoService.saveOrUpdate(bookInfo));
	}

	/**
	* 删除 
	*/
	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入ids", position = 7)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestBody Integer[] ids) {
		return R.status(bookInfoService.deleteBatch(Arrays.asList(ids)));
	}

}
